package com.efrei.uchat.model.croom;

import java.util.HashSet;
import java.util.Set;

import com.efrei.uchat.io.Session;

public class Croom {
	
	// chat room name
	private String topic;
	// null if not password
	private String password;
	// chat room users
	private Set<Session> sessions = new HashSet<Session>();
	
	public Croom(String name) {
		super();
		this.topic = name;
		this.password = null;
	}
	
	public Croom(String name, String password) {
		super();
		this.topic = name;
		this.password = password;
	}
	
	@Override
	public String toString() {
		return getTopic();
	}
	
	@Override
	public boolean equals(Object obj) {
		return topic.equals(obj);
	}
	
	/**
	 * specify if croom required password
	 * @return croom status
	 */
	public boolean isPrivate() {
		return password != null;
	}
	
	public void addSession(Session session) {
		sessions.add(session);
	}
	
	/**
	 * @param session
	 * @return if a session was removed
	 */
	public boolean removeSession(Session session) {
		return sessions.remove(session);
	}
	
	public int getNbSessions() {
		return sessions.size();
	}

	public String getTopic() {
		return topic;
	}
	
	public Set<Session> getSessions() {
		return sessions;
	}

	public void setTopic(String topic) {
		this.topic = topic;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public boolean contains(Session session) {
		return sessions.contains(session);
	}
}
